﻿using ServiceCore.DbContext;
using ServiceCore.Entity.Core;
using ServiceCore.Entity.Model;
using ServiceCore.Entity.Param.Tag;

namespace ServiceCore.Service
{
    public partial class TagService : SqlsugarServices<TagInfo>
    {
        public BaseParam<TagInfo, long> Tag_Save_Common_Verify(BaseParam<TagInfo, long> arg)
        {
            if (arg == null)
                return new BaseParam<TagInfo, long>("参数不能为空");
            if (arg.Param == null)
                return new BaseParam<TagInfo, long>("参数不能为空");
            if (arg.Param.TagTypeId == 0)
                return new BaseParam<TagInfo, long>("标签类型id不能为空");
            if (string.IsNullOrEmpty(arg.Param.Name))
                return new BaseParam<TagInfo, long>("标签名称不能为空");
            //if (arg.Param.CreateUserId == 0)
            //    return new BaseParam<TagInfo, long>("创建人不能为空");

            return arg;
        }

        public BaseParam<TagInfo, long> Tag_Add_Verify(BaseParam<TagInfo, long> arg)
        {
            arg = Tag_Save_Common_Verify(arg);
            if (string.IsNullOrEmpty(arg.ErrorMsg) == false)
                return arg;

            var argUser = new BaseParam<TagInfo, TagInfo>();
            argUser.Param = arg.Param;
            Tag_Exists(argUser, true);
            if (argUser.Data != null)
                return new BaseParam<TagInfo, long>("标签名称已存在");

            arg.Param.CreateTime = DateTime.Now;
            return arg;
        }

        public BaseParam<TagInfo, long> Tag_Edit_Verify(BaseParam<TagInfo, long> arg)
        {
            arg = Tag_Save_Common_Verify(arg);
            if (string.IsNullOrEmpty(arg.ErrorMsg) == false)
                return arg;
            if (arg.Param.Id == 0)
                return new BaseParam<TagInfo, long>("id不能为空");

            var argUser = new BaseParam<TagInfo, TagInfo>();
            argUser.Param = arg.Param;
            Tag_Exists(argUser, false);
            if (argUser.Data != null)
                return new BaseParam<TagInfo, long>("标签名称已存在");

            return arg;
        }

        public BaseParam<TagDeleteParam, long> Tag_Del_Verify(BaseParam<TagDeleteParam, long> arg)
        {
            if (arg == null)
                return new BaseParam<TagDeleteParam, long>("参数不能为空");
            if (arg.Id == 0)
                return new BaseParam<TagDeleteParam, long>("id不能为空");

            return arg;
        }
    }
}
